//
//  VIPMallService.swift
//  LeGou
//
//  Created by lxm on 2022/8/5.
//

import Foundation
class VIPMallService {
    private init(){}
    static let shared = VIPMallService()
    
    typealias Cate = VIPMallModels.Cate
    
    var loadCategoryDis : Disposable?
    
    var cates : [Cate]?
    
    func loadCategory(complete : @escaping ((_ ok : Bool)->())) {
        loadCategoryDis?.dispose()
        if let cates = cates {
            complete(true)
        } else {
            loadCategoryDis = VIPMallAPI.category.rxRequest(type:[Cate].self).subscribe(onNext:{ [unowned self] resp in
                self.cates = resp.first?.child
                complete(true)
            }, onError: { _ in
                complete(false)
            })
        }
    }
    
    // 支付类型转为支付类型字符串
    func getPayStr(type : EnumPayTool) -> String {
        var payTypeStr = ""
        switch type {
            case .alipay:
            payTypeStr = "alipay"
                break;
            case .wechat:
            payTypeStr = "weixin"
                break;
            case .balancePay:
                payTypeStr = "yue"
            case .ckPay:
                payTypeStr = "mallYue"
            case .integral:
                payTypeStr = "integral"
        }
        return payTypeStr
    }
}

